﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using EQ1.Elements;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Controls {
  public class InvSlot : Control , IUIElement<InvSlot> {
    public InvSlot ( UIDocument doc , string name )
      : base( doc , name ) {
      this.ItemOffsetX = 0;
      this.ItemOffsetY = 0;
    }
    public InvSlot ( UIDocument doc )
      : this( doc , "InvSlot" ) {
    }

    #region IUIElement<InvSlot> Members

    public void Validate ( InvSlot val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        InvSlot el = new InvSlot( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( InvSlot val ) {
      base.Copy( val );

      this.ItemOffsetX = val.ItemOffsetX;
      this.ItemOffsetY = val.ItemOffsetY;

      if( val.Background != null )
        this.Background = val.Background;
    }

    #endregion

    public string Background {
      get {
        return this.GetElement( "Background" ).InnerText;
      }
      set {
        this.Validate( "Background" , value );
      }
    }
    public int ItemOffsetX {
      get {
        return int.Parse( this.GetElement( "ItemOffsetX" ).InnerText );
      }
      set {
        this.Validate( "ItemOffsetX" , value.ToString() );
      }
    }
    public int ItemOffsetY {
      get {
        return int.Parse( this.GetElement( "ItemOffsetY" ).InnerText );
      }
      set {
        this.Validate( "ItemOffsetY" , value.ToString() );
      }
    }
  }
}
